const Sequelize = require('sequelize');
const sequelize = new Sequelize({
  host: process.env.DB_HOST,
  dialect: 'mysql',
  username: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
});


const User = require('./User')(sequelize, Sequelize.DataTypes);
const Task = require('./Task')(sequelize, Sequelize.DataTypes);  // 导入 Task 模型

const db = {
  sequelize,
  Sequelize,
  User,
  Task
};

// 同步数据库
sequelize.sync({ force: false })  // 如果你想强制删除并重新创建表，设置 force: true
  .then(() => console.log('Database & tables synchronized'))
  .catch(err => console.log('Error syncing database: ', err));

module.exports = db;
